package dragon.tagext.easyui;

import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import dragon.core.util.GlobalParameter;
import dragon.core.util.StringUtils;
import dragon.model.bizObject.BizField;
import dragon.model.bizObject.BizObject;
import dragon.model.bizObject.QueryField;
import dragon.model.fieldTemplate.FieldTemplateDao;
import dragon.modules.system.config.dao.SysConfig;

@SuppressWarnings("serial")
public class Mod extends BodyTagSupport {

	private String js;
	private String html;

	@Override
	public int doStartTag() throws JspException {
		BizObject bizObject = (BizObject) pageContext.getRequest().getAttribute("bizObject");
		String windowID = "DefaultMod";
		String template = pageContext.getRequest().getParameter("template");
		if (!StringUtils.isEmpty(template)) {
			template = template.trim().toLowerCase();
			if ("tabslave,treeslave".contains(template.trim().toLowerCase()))
				windowID = "ModSlave";
		}
		try {
			if (bizObject != null) {

				StringBuffer queryString = new StringBuffer();
				if (bizObject.getQueryFields() != null) {
					for (QueryField qf : bizObject.getQueryFields()) {
						queryString.append("&").append(qf.getCode().toUpperCase()).append("=").append(pageContext.getRequest().getParameter(qf.getCode().toUpperCase()));
					}
					if (queryString.length() > 0)
						queryString.deleteCharAt(0);
				}

				StringBuffer sb_js = new StringBuffer();
				StringBuffer sb_html = new StringBuffer();

				sb_js.append("var kindeditors = new Map();\n");
				sb_js.append("var fieldsType = new Map();\n");
				sb_js.append("$(function() {\n");
				// 添加用户初始化fun
				sb_js.append("\tif($.isFunction(window.init_before))").append("{\n\t\tinit_before();\n\t}\n");
				// from表单开始
				sb_js.append("\t$('#myform').form({\n");
				sb_js.append("\t\turl : 'dragon/model/action/BizObjectHandler/mod.ejw',\n");
				sb_js.append("\t\tonSubmit : function() {\n");
				sb_js.append("\t\t\ttop.showProgress();\n");
				sb_js.append("\t\t\tvar isValid = $(this).form('validate');\n");
				sb_js.append("if(window.before_submit){if(!before_submit()){isValid = false;}}");
				sb_js.append("\t\t\tif(!isValid){top.hideProgress();}\n");
				sb_js.append("\t\t\treturn isValid;\n");

				sb_js.append("\t\t},\n");
				sb_js.append("\t\tsuccess : function(data) {\n");
				sb_js.append("\t\t\ttop.hideProgress();");

				sb_js.append("\t\t\ttry{\n\t\t\t\tdata = eval('(' + data + ')');\n\t\t\t}catch(e){\n\t\t\t\ttop.showErrorMsg(\"出错了\", data);\n\t\t\t\treturn;\n\t\t\t}\n");
				sb_js.append("\t\t\tif(data.MESSAGE_ERROR != ''){\n\t\t\t\ttop.showMsg(\"错误\", data.MESSAGE_ERROR, true,'error');\n");
				sb_js.append("\t\t\t}else if(data.MESSAGE_WARNING != ''){\n\t\t\t\ttop.showMsg(\"警告\", data.MESSAGE_WARNING, true,'warning');\n");
				sb_js.append("\t\t\t}else{\n\t\t\t\tif(data.MESSAGE_INFO != ''){\n\t\t\t\t\ttop.showMsg(\"\", data.MESSAGE_INFO, false);\n\t\t\t\t}else{\n\t\t\t\t\ttop.showMsg(\"\",\"修改成功！\", false); \n\t\t\t\t}\n");
				if (StringUtils.isEmpty(template)) {
					sb_js.append("\t\t\ttop.$('#tabsconetnt').tabs('getSelected').find('iframe')[0].contentWindow.$('#mydatagrid').datagrid('reload');\n");
				} else if ("slave".equals(template)) {
					sb_js.append("\t\t\ttop.getWindow('DefaultMod').$('#mydatagrid_").append(bizObject.getCode()).append("').datagrid('reload');\n");
				} else if ("tabslave".equals(template)) {
					sb_js.append("\t\t\ttop.getWindow('DefaultMod').$('#tabs').tabs('getSelected').find('iframe')[0].contentWindow.$('#mydatagrid').datagrid('reload');\n");
				} else if ("treeslave".equals(template)) {
					sb_js.append("\t\t\ttop.$('#tabsconetnt').tabs('getSelected').find('iframe')[0].contentWindow.$('#slave_").append(bizObject.getCode())
							.append("').find('iframe')[0].contentWindow.$('#mydatagrid').datagrid('reload');\n");
					sb_js.append("\t\t\ttop.$('#tabsconetnt').tabs('getSelected').find('iframe')[0].contentWindow.refreshLeftTree();");
				}

				sb_js.append("if(closewindow){");
				sb_js.append("\t\t\ttop.closeWindow('" + windowID + "');\n");
				sb_js.append("}\nafterSave(data.parameters);");

				sb_js.append("\t\t\t}\n");
				sb_js.append("\t\t}\n");
				sb_js.append("\t});\n");

				// 字段类型
				if (!bizObject.getBizFields().isEmpty()) {
					for (BizField bf : bizObject.getBizFields()) {
						if (bf.getFieldTemplate() != null) {
							switch (bf.getFieldTemplate().getType()) {
							case DATETIME:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','datebox');\n");
								break;
							case DATE:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','datebox');\n");
								break;
							case TIME:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','timespinner');\n");
								break;
							case SELECT:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','combotree").append(bf.getFieldTemplate().getMultiple() == 0 ? "" : "-multiple")
										.append("');\n");
								break;
							case RADIO:
								if (bf.getFieldTemplate().getProto() == 1) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','radio');\n");
								} else if (bf.getFieldTemplate().getProto() == 0) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','combobox").append(bf.getFieldTemplate().getMultiple() == 0 ? "" : "-multiple")
											.append("');\n");
								}
								break;
							case CHECKBOX:
								if (bf.getFieldTemplate().getProto() == 1) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','checkbox');\n");
								} else if (bf.getFieldTemplate().getProto() == 0) {
									sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','combobox").append(bf.getFieldTemplate().getMultiple() == 0 ? "" : "-multiple")
											.append("');\n");
								}
								break;
							default:
								sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','text');\n");
								break;
							}
						} else {
							sb_js.append("\tfieldsType.put('").append(bf.getCode().toUpperCase()).append("','text');\n");
						}
					}
				}
				// 字段模板
				if (!bizObject.getBizFields().isEmpty()) {
					sb_js.append("\tvar value = '';\n");
					for (BizField bf : bizObject.getBizFields()) {
						if (bf.getFieldTemplate() != null) {
							switch (bf.getFieldTemplate().getType()) {
							case DATETIME:
								sb_js.append("\t$('#").append(bf.getCode()).append("').datebox({");
								sb_js.append("formatter : function(date) {");
								sb_js.append("return date.Format(\"").append(bf.getFieldTemplate().getFormat()).append("\");");
								sb_js.append("}");
								sb_js.append("});\n");
								break;
							case DATE:
								sb_js.append("\t$('#").append(bf.getCode()).append("').datebox({");
								sb_js.append("formatter : function(date) {");
								sb_js.append("return date.Format(\"").append(bf.getFieldTemplate().getFormat()).append("\");");
								sb_js.append("}");
								sb_js.append("});\n");
								break;
							case SELECT:
								sb_js.append("\t$('#").append(bf.getCode().toUpperCase()).append("').combotree({");
								sb_js.append("onBeforeSelect : function(node) {");
								sb_js.append("if(node.state!=undefined&&").append(bf.getFieldTemplate().getOnlyLeafSelect() == 1 ? "true" : "false").append("){return false;}},");
								sb_js.append("onLoadSuccess : function(node, data) {");
								sb_js.append("var tree = $('#").append(bf.getCode().toUpperCase()).append("').combotree('tree');");
								sb_js.append("var roots = tree.tree('getRoots');");
								sb_js.append("for ( var i = roots.length - 1; i >= 0; i--) {tree.tree('expandAll', roots[i].target);}roots = null;	tree = null;");
								sb_js.append("}});\n");
								break;
							case RICHTEXT:
								sb_js.append("\tvar ").append(bf.getCode()).append("id;");
								sb_js.append("$.getScript('plugins/").append(SysConfig.getParameter(GlobalParameter.KindeditorRelease)).append("/kindeditor-min.js', function() {");
								sb_js.append("KindEditor.basePath = 'plugins/").append(SysConfig.getParameter(GlobalParameter.KindeditorRelease)).append("/';");
								sb_js.append(bf.getCode()).append(" = ").append("KindEditor.create('textarea[name=\"").append(bf.getCode().toUpperCase()).append("\"]');");
								sb_js.append("kindeditors.put('").append(bf.getCode()).append("',").append(bf.getCode()).append(");");
								sb_js.append("});\n");
								break;
							case CHECKBOX:
								if (bf.getFieldTemplate().getProto() == 0) {
									sb_js.append("\tvalue = '").append(bf.getValue() == null ? "" : bf.getValue()).append("';");
									sb_js.append("if(value!=''){");
									sb_js.append("$('#").append(bf.getCode().toUpperCase()).append("').combobox('setValues',value.split(\",\"));");
									sb_js.append("}\n");
								}
								break;
							default:
								break;
							}
						}
					}
					sb_js.append("\tif($.isFunction(window.init_after))").append("{\n\tinit_after();\n\t}\n");
					sb_js.append("});\n");

					// js部分结束

					// html部分开始
					sb_html.append("<form id=\"myform\" method=\"post\"");
					if (bizObject.isHasFileField()) {
						sb_html.append(" enctype=\"multipart/form-data\"");
					}
					sb_html.append(">\n");
					sb_html.append("\t<input type=\"hidden\" id=\"bizCode\" name=\"bizCode\" value=\"").append(bizObject.getCode()).append("\" />\n");
					for (BizField bf : bizObject.getBizFields()) {
						if (bf.getIsVisible() == 0 && bf.getIsFormField() == 1) {
							sb_html.append("\t<input type=\"hidden\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase()).append("\" value=\"")
									.append(bf.getValue() == null ? "" : bf.getValue()).append("\" />\n");
						}
					}
					sb_html.append("\t<table width=\"100%\" border=\"0\">\n");
					int fieldsNumCurrentRow = 0;
					for (BizField bf : bizObject.getBizFields()) {
						// 便于jsp页面中取数据
						pageContext.setAttribute(bf.getCode().toUpperCase(), bf.getValue());

						if (bf.getIsVisible() == 1 && bf.getIsFormField() == 1) {
							fieldsNumCurrentRow += 1;
							boolean required = (bf.getIsPrimaryKey() == 1 || bf.getIsMandatory() == 1) ? true : false;
							boolean readonly = (bf.getCanUpdate() == 0 || bf.getIsReadonly() == 1) ? true : false;
							if (fieldsNumCurrentRow == 1)
								sb_html.append("\t\t<tr>\n");
							sb_html.append("\t\t\t<td  align=\"right\" width=\"").append(100 / bizObject.getMaxFieldsNumPerRow() * 0.25).append("%\" >\n\t\t\t\t").append(bf.getName())
									.append(required ? ":<font color=\"red\">*</font>\n\t\t\t</td>\n" : ":&nbsp;\n\t\t\t</td>\n");
							sb_html.append("\t\t\t<td width=\"")
									.append(100 / bizObject.getMaxFieldsNumPerRow() * 0.75)
									.append("%\" colspan=\"")
									.append(bf.getFieldTemplate() != null && (bf.getFieldTemplate().getType().name().equals("LONGTEXT") || bf.getFieldTemplate().getType().name().equals("RICHTEXT")) ? bizObject
											.getMaxFieldsNumPerRow() * 2 - 1 : 1).append("\">\n");

							if (bf.getFieldTemplate() == null && bf.getType().name().endsWith("CHAR")) {

								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" class=\"easyui-validatebox\" ").append(required ? "required=\"true\" " : " ").append(" value=\"")
										.append(bf.getValue() == null ? "" : bf.getValue()).append("\" ").append(bf.getValidType()).append(readonly ? " readonly=\"readonly\" />" : " />\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate() == null && (bf.getType().name().startsWith("INT") || bf.getType().name().equals("DECIMAL"))) {

								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" class=\"easyui-numberbox\" ").append(bf.getValidType()).append(required ? " required=\"true\" " : " ").append(" value=\"")
										.append(bf.getValue() == null ? "" : bf.getValue()).append("\" ").append(readonly ? " readonly=\"readonly\" " : " ")
										.append(bf.getMinValue() == null ? "" : "min=\"" + bf.getMinValue() + "\"").append(bf.getMaxValue() == null ? "" : "max=\"" + bf.getMaxValue() + "\"")
										.append(" title=\"").append(bf.getMinValue() == null ? "" : "最小值:" + bf.getMinValue()).append(bf.getMaxValue() == null ? "" : "最大值:" + bf.getMaxValue())
										.append("\" />\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().endsWith("TEXT")) {

								sb_html.append("\t\t\t\t<textarea style=\"width:100%;").append("\" id=\"").append(bf.getCode().toUpperCase()).append(" \" name=\"").append(bf.getCode().toUpperCase())
										.append("\"  class=\"easyui-validatebox\"").append(required ? " required=\"true\" " : " ").append(bf.getValidType())
										.append(readonly ? " readonly=\"readonly\" >" : " >").append(bf.getValue() == null ? "" : bf.getValue()).append("</textarea>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("DATETIME") || bf.getFieldTemplate().getType().name().equals("DATE")) {
								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-")
										.append(bf.getFieldTemplate().getType().name().equals("DATE") ? "datebox" : "datetimebox").append("\" ").append(bf.getValidType())
										.append(required ? " required=\"true\" " : " ").append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue()).append("\" ")
										.append(readonly ? " disabled=\"true\" />" : " />\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearDatebox('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("TIME")) {
								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-timespinner\" showSeconds=\"true\" ").append(bf.getValidType())
										.append(required ? " required=\"true\" " : " ").append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue()).append("\" ")
										.append(readonly ? " disabled=\"true\" />" : " />\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearTime('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("SELECT")) {
								sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
										.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-combotree\" ")
										.append(" url=\"dragon/model/action/FieldTemplateHandler/loadData.ejw?bizCode=").append(bizObject.getCode()).append("&").append(queryString)
										.append("&bizfield").append("=").append(bf.getCode()).append("&root=").append(bf.getFieldTemplate().getDicRoot()).append("\" ")
										.append(bf.getFieldTemplate().getMultiple() == 1 ? " multiple=\"true\" " : "").append(bf.getValidType()).append(required ? " required=\"true\" " : " ")
										.append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue()).append("\" ").append(readonly ? " disabled=\"true\" />" : " />\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearCombo('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("RADIO") || bf.getFieldTemplate().getType().name().equals("CHECKBOX")) {
								if (bf.getFieldTemplate().getProto() == 0) {
									sb_html.append("\t\t\t\t<input type=\"text\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
											.append("\" style=\"width: 150px;\" editable=\"false\" class=\"easyui-combobox\" valueField=\"VALUE\" textField=\"TEXT\"  ")
											.append(" url=\"dragon/model/action/FieldTemplateHandler/loadData.ejw?bizCode=").append(bizObject.getCode()).append("&").append(queryString)
											.append("&bizfield").append("=").append(bf.getCode()).append("\" ").append(bf.getFieldTemplate().getMultiple() == 1 ? " multiple=\"true\" " : "")
											.append(bf.getValidType()).append(required ? " required=\"true\" " : " ").append(" value=\"").append(bf.getValue() == null ? "" : bf.getValue())
											.append("\" ").append(readonly ? " disabled=\"true\" />" : " />\n");
									sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearCombo('")
											.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
									sb_html.append("\t\t\t</td>\n");
								} else {
									if (bf.getFieldTemplate().getType().name().equals("RADIO")) {
										if (bf.getFieldTemplate().getOptionsList() == null || bf.getFieldTemplate().getOptionsList().size() == 0) {
											for (Map<String, Object> map : FieldTemplateDao.getData(bizObject.getCode(), bf.getCode(), null, queryString.toString())) {
												sb_html.append("\t\t\t\t<input type='radio' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ")
														.append(map.get("VALUE").toString().trim().equals(bf.getValue() == null ? "" : bf.getValue().trim()) ? "checked" : "unchecked").append(" />")
														.append(map.get("TEXT")).append("\n");
											}
										} else {
											for (Map<String, Object> map : bf.getFieldTemplate().getOptionsList()) {
												sb_html.append("\t\t\t\t<input type='radio' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ")
														.append(map.get("VALUE").toString().trim().equals(bf.getValue() == null ? "" : bf.getValue().trim()) ? "checked" : "unchecked").append(" />")
														.append(map.get("TEXT")).append("\n");
											}
										}
									} else {
										if (bf.getFieldTemplate().getOptionsList() == null || bf.getFieldTemplate().getOptionsList().size() == 0) {
											for (Map<String, Object> map : FieldTemplateDao.getData(bizObject.getCode(), bf.getCode(), null, queryString.toString())) {
												sb_html.append("\t\t\t\t<input type='checkbox' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ").append(" />").append(map.get("TEXT")).append("\n");
											}
										} else {
											for (Map<String, Object> map : bf.getFieldTemplate().getOptionsList()) {
												sb_html.append("\t\t\t\t<input type='checkbox' id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase())
														.append("\" value=\"").append(map.get("VALUE")).append("\" ").append(" />").append(map.get("TEXT")).append("\n");
											}
										}
										sb_html.append("\t\t\t\t<script>setValuesText('").append(bf.getCode().toUpperCase()).append("','").append(bf.getValue()).append("')</script>\n");
									}
									sb_html.append("\t\t\t</td>\n");
								}
							} else if (bf.getFieldTemplate().getType().name().equals("BDSELECTOR")) {
								sb_html.append("\t\t\t\t<input id='").append(bf.getCode().toUpperCase()).append("' name='").append(bf.getCode().toUpperCase()).append("' type='hidden' value='")
										.append(bf.getValue()).append("' />\n");
								sb_html.append("\t\t\t\t<input style=\"width: 150px;\" id=\"").append(bf.getCode().toUpperCase()).append("_Text\" name=\"").append(bf.getCode().toUpperCase())
										.append("_Text\" type='text' class='easyui-validatebox'  readonly=\"readonly\" ").append(bf.getValidType()).append(required ? " required=\"true\"" : "")
										.append(" value='").append(bf.getText()).append("' ").append(" />\n");
								sb_html.append("\t\t\t\t<a id=\"bdselector\" href=\"javascript:void(0);\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-add\" onclick=\"chooseBD('"
										+ windowID + "','");
								sb_html.append(bf.getCode().toUpperCase()).append("','").append(bf.getFieldTemplate().getCode()).append("','").append(bf.getFieldTemplate().getName()).append("',");
								sb_html.append(bf.getFieldTemplate().getWindowWidth()).append(",").append(bf.getFieldTemplate().getWindowHeight()).append(",")
										.append(bf.getFieldTemplate().getMaximizable()).append(",").append(bf.getFieldTemplate().getMaximize()).append(");\" >选择</a>\n");
								sb_html.append("\t\t\t\t<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearText('")
										.append(bf.getCode().toUpperCase()).append("');\"").append(readonly ? "disabled" : "").append(">清除</a>\n");
								sb_html.append("\t\t\t</td>\n");
							} else if (bf.getFieldTemplate().getType().name().equals("FILE")) {
								sb_html.append("<input type=\"hidden\" id=\"").append(bf.getCode().toUpperCase()).append("\" name=\"").append(bf.getCode().toUpperCase()).append("\" value=\"")
										.append(bf.getValue()).append("\"/>");
								sb_html.append("<input type=\"hidden\" id=\"").append(bf.getCode().toUpperCase()).append("_DELLIST\" name=\"").append(bf.getCode().toUpperCase())
										.append("_DELLIST\"/>");
								sb_html.append("<div id=\"").append(bf.getCode().toUpperCase()).append("_FILELIST\">");
								if (!StringUtils.isEmpty(bf.getValue())) {
									int index = 0;
									for (String s : bf.getValue().split(",")) {
										String[] fileinfo = s.split(":");
										String filestorename = fileinfo[0].substring(bizObject.getCode().toString().length() + 1, fileinfo[0].length());
										sb_html.append("<div id=\"")
												.append(bf.getCode().toUpperCase())
												.append("_OLDFILE_" + index + "\" filestorename=\"")
												.append(filestorename)
												.append("\"><a href=\"dragon/model/action/BizObjectHandler/getFile.ejw?path=" + s + "\" target=\"_blank\">" + fileinfo[1]
														+ "</a><a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-cancel\" onclick=\"delFile('")
												.append(bf.getCode().toUpperCase()).append("_OLDFILE_" + index + "','" + filestorename + "');\">清除</a></div>");
										index += 1;
									}
								}
								sb_html.append("</div>");

								sb_html.append("<input id=\"").append(bf.getCode().toUpperCase()).append("_FILENUM\" type=\"hidden\" value=\"0\" />");
								sb_html.append("<input id=\"").append(bf.getCode().toUpperCase()).append("_FILENUM_0\" name=\"").append(bf.getCode().toUpperCase())
										.append("_FILENUM_0\" type=\"file\" style=\"display: none;\" onchange=\"setFilePath(this,'").append(bf.getCode().toUpperCase()).append("_FILENUM_0_PATH','")
										.append(bf.getFieldTemplate().getMultiple()).append("')\" accept=\"").append(bf.getFieldTemplate().getAcceptFileType()).append("\"/>");
								sb_html.append("<input id=\"").append(bf.getCode().toUpperCase()).append("_FILENUM_0_PATH\" type=\"text\" />");
								sb_html.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"ext-icon-upload\" onclick=\"upload('")
										.append(bf.getCode().toUpperCase()).append("_FILENUM_0');\">上传</a>");
								sb_html.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"icon-remove\" onclick=\"clearFilePath('")
										.append(bf.getCode().toUpperCase()).append("_FILENUM_0');\">清除</a>");
								if (bf.getFieldTemplate().getMultiple() == 1) {
									sb_html.append("<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" plain=\"true\" iconCls=\"ext-icon-file_add\" onclick=\"addUpload('")
											.append(bf.getCode().toUpperCase()).append("_FILENUM','").append(bf.getFieldTemplate().getAcceptFileType()).append("');\">增加</a>");
								}
							}
							if (fieldsNumCurrentRow == bf.getAdjacentFieldsNum()) {
								fieldsNumCurrentRow = 0;
								sb_html.append("\t\t</tr>\n");
							}
						}
					}
					sb_html.append("\t</table>\n");
					sb_html.append("</form>\n");
					sb_html.append("<table width=\"95%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"dialog_button_bar\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td>\n");
					sb_html.append("\t\t\t\t<div align=\"right\">\n");
					sb_html.append("\t\t\t\t\t<a href=\"javascript:void(0);\" class=\"easyui-linkbutton\" iconCls=\"icon-ok\" onclick=\"save();\" title=\"保存后关闭窗口\">确定</a>\n");
					sb_html.append("<a href=\"javascript:void(0);\" class=\"easyui-linkbutton\" iconCls=\"icon-ok\" onclick=\"save(false);\" title=\"保存后不关闭窗口\">保存</a>");
					sb_html.append("\t\t\t\t\t<a href=\"javascript:void(0);\"  class=\"easyui-linkbutton\" iconCls=\"icon-cancel\" onclick=\"top.closeWindow('" + windowID + "');\">关闭</a>\n");
					sb_html.append("\t\t\t\t</div>\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n");

					js = sb_js.toString();
					html = sb_html.toString();
				}

			} else {
				js = "$(function(){top.showMsg(\"\", \"未发现数据模型：！\", false);});";
				html = "<font color=\"red\">未发现模型：</font>";
			}

			pageContext.setAttribute("js", js);
			pageContext.setAttribute("html", html);
		} catch (Exception e) {
			throw new JspException(e);
		}

		return EVAL_BODY_INCLUDE;
	}

	public String getJs() {
		return js;
	}

	public void setJs(String js) {
		this.js = js;
	}

	public String getHtml() {
		return html;
	}

	public void setHtml(String html) {
		this.html = html;
	}
}
